package com.keyinong.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.keyinong.bluetooth.BluetoothService;
import com.keyinong.qudan.R;

public class ShezhiFragment extends Fragment{
	private EditText et_1;
	private EditText et_2;
	private EditText et_3;
	private EditText et_4;
	private Button btn_queren;
//	private Button btn_bluetooth;
	private String num1;
	private String num2;
	private String num3;
	private String num4;
	public static BluetoothService mService = null;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_shezhi, null);
	}
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		initRes();
	}
	private void initRes() {
		et_1=(EditText)getView().findViewById(R.id.et_1);
		et_2=(EditText)getView().findViewById(R.id.et_2);
		et_3=(EditText)getView().findViewById(R.id.et_3);
		et_4=(EditText)getView().findViewById(R.id.et_4);
		btn_queren=(Button)getView().findViewById(R.id.btn_queren);
		btn_queren.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				num1=et_1.getText().toString();
				num2=et_2.getText().toString();
				num3=et_3.getText().toString();
				num4=et_4.getText().toString();
				if(num1.equals("")||num2.equals("")||num3.equals("")||num4.equals("")){
					Toast.makeText(getActivity(), "请填写正确的IP地址", Toast.LENGTH_SHORT).show();
				}else {
					SharedPreferences spuser = getActivity().getSharedPreferences("spuser",
						Context.MODE_PRIVATE);
				Editor editoruser = spuser.edit();
				editoruser.putString("num1", num1);
				editoruser.putString("num2", num2);
				editoruser.putString("num3", num3);
				editoruser.putString("num4", num4);
				editoruser.commit();
				Toast.makeText(getActivity(), "保存成功", Toast.LENGTH_SHORT).show();
				}
				
			}
		});
	}
}
